﻿using Code;
using github.heerheer.card2.UI.Views;
using HeerCards;
using HeerCards.Info;
using LitJson;
using PropertyChanged;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Linq;

namespace github.heerheer.card2.UI.ViewModels
{
    [AddINotifyPropertyChangedInterface]
    public class PoolContentViewModel : INotifyPropertyChanged
    {
        public HCPool Pool { get; set; }
        public ObservableCollection<OBLevel> PLevelCollections { get; set; }
        public VIPInfo ProInfo { get; set; } = AppMain.VipInfo;

        public event PropertyChangedEventHandler PropertyChanged;

        public void LoadPoolContent(string pool)
        {
            this.Pool = JsonMapper.ToObject<HCPool>(File.ReadAllText(App.getPoolPath(pool)));
            PLevelCollections = new ObservableCollection<OBLevel>(Pool.LevelCollections.Select(s => new OBLevel()
            {
                Description = s.Description,
                miniG = s.miniG,
                Name = s.Name,
                Ratio = s.Ratio,
                useImage = s.useImage,
                OBCards = new ObservableCollection<HCCard>(s.Cards),
                Cards = s.Cards
            }));
        }
    }
}